package com.example.tfliteonwatch;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;

public class multiChoose extends AppCompatActivity {

    private TextView mTextView;

    private Button  walking;
    private Button  jogging;
    private Button  stairs;
    private Button  sitting;
    private Button  standing;
    private Button  typing;
    private Button  writing;
    private Button  Clapping;
    private Button  confirm;
    private int count=0;
    private ArrayList<Button> buttonlist=new ArrayList<>();
    public void addAction(String action){
        para.action.add(action);
        count++;
    }
    public void deleteAction(String action){
        para.action.remove(para.action.indexOf(action));
        count--;
    }
    static int boolToInt(boolean b) {
        if(b)
            return 1;
        return 0;
    }
    public void afterclick(Button b){
        Log.d("",b.getText().toString().split(" ")[0]);
        switch (boolToInt(para.action.contains(b.getText().toString().split(" ")[0]))){
            case 0:
//                        PPG.setActivated(false);
                addAction(b.getText().toString());
                b.setBackgroundResource(R.drawable.shape2);

                break;
            case 1:
//                        PPG.setActivated(true);
                Log.d("","点过了");
                deleteAction(b.getText().toString().split(" ")[0]);
                b.setBackgroundResource(R.drawable.shape);

                break;
        }
        resetText();
        setText();
    }
    public void resetText(){
        walking.setText("walking");
        jogging.setText("jogging");
//        stairs.setText("stairs");
        sitting.setText("sitting");
//        standing.setText("standing");
        typing.setText("typing");
        writing.setText("writing");
        Clapping.setText("Clapping");
    }
    public void setText(){
        int i=0;
        resetText();
        for(String s:para.action)
        {
            for(Button b :buttonlist){
                if(b.getText().toString().equals(s)){
                    i++;
                    b.setText(s+" "+i);
                }
            }
        }


    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        para.action.clear();
        para.setTimeIndex=0;
        para.timelist.clear();
        setContentView(R.layout.activity_multi_choose);
        Log.d("","jinlaile");
        walking=(Button) findViewById(R.id.walking);
        walking.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                afterclick(walking);
            }
        });

        jogging=(Button) findViewById(R.id.jogging);
        jogging.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                afterclick(jogging);
//                setAction(1);
//                Intent intent=new Intent(action.this, setTime.class);
//                startActivity(intent);
            }
        });

//        stairs=(Button) findViewById(R.id.stairs);
//        stairs.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                afterclick(stairs);
////                setAction(2);
////                Intent intent=new Intent(action.this, setTime.class);
////                startActivity(intent);
//            }
//        });

        sitting=(Button) findViewById(R.id.sitting);
        sitting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                afterclick(sitting);
//                setAction(3);
//                Intent intent=new Intent(action.this, setTime.class);
//                startActivity(intent);
            }
        });

//        standing=(Button) findViewById(R.id.standing);
//        standing.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                afterclick(standing);
////                setAction(4);
////                Intent intent=new Intent(action.this, setTime.class);
////                startActivity(intent);
//            }
//        });

        typing=(Button) findViewById(R.id.typing);
        typing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                afterclick(typing);
//                setAction(5);
//                Intent intent=new Intent(action.this, setTime.class);
//                startActivity(intent);
            }
        });

        writing=(Button) findViewById(R.id.writing);
        writing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                afterclick(writing);
//                setAction(6);
//                Intent intent=new Intent(action.this, setTime.class);
//                startActivity(intent);
            }
        });

        Clapping=(Button) findViewById(R.id.Clapping);
        Clapping.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                afterclick(Clapping);
//                setAction(7);
//                Intent intent=new Intent(action.this, setTime.class);
//                startActivity(intent);
            }
        });
        confirm=(Button) findViewById(R.id.confirm);
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

//                setAction(7);
                Intent intent=new Intent(multiChoose.this, setTime.class);
                startActivity(intent);
            }
        });

        buttonlist.add(walking);
        buttonlist.add(jogging);
//        buttonlist.add(stairs);
        buttonlist.add(sitting);
//        buttonlist.add(standing);
        buttonlist.add(typing);
        buttonlist.add(writing);
        buttonlist.add(Clapping);
    }
}